import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEField } from './ipsdefield';
import { IPSLinkDEField } from './ipslink-defield';
import { PSDEFieldImpl } from './psdefield-impl';
import { IPSDERBase } from '../der/ipsderbase';

export class PSLinkDEFieldImpl extends PSDEFieldImpl implements IPSLinkDEField {
  protected psder: IPSDERBase | null = null;

  getPSDER(): IPSDERBase | null {
    if (this.psder != null) return this.psder;
    const value = this.M.getPSDER;
    if (value == null) {
      return null;
    }
    this.psder = this.getPSModel4('dataentity.der.IPSDERBase', value, 'getPSDER') as IPSDERBase;
    return this.psder;
  }

  get psDER(): IPSDERBase | null {
    return this.getPSDER();
  }

  getPSDERMust(): IPSDERBase {
    const value = this.getPSDER();
    if (value == null) {
      throw new Error('未指定实体关系对象');
    }
    return value;
  }

  protected realpsdefield: IPSDEField | null = null;

  getRealPSDEField(): IPSDEField | null {
    if (this.realpsdefield != null) return this.realpsdefield;
    const value = this.M.getRealPSDEField;
    if (value == null) {
      return null;
    }
    this.realpsdefield = this.getRealPSDataEntityMust().findPSDEField(value);
    return this.realpsdefield;
  }

  get realPSDEField(): IPSDEField | null {
    return this.getRealPSDEField();
  }

  getRealPSDEFieldMust(): IPSDEField {
    const value = this.getRealPSDEField();
    if (value == null) {
      throw new Error('未指定实际链接物理属性');
    }
    return value;
  }

  protected realpsdataentity: IPSDataEntity | null = null;

  getRealPSDataEntity(): IPSDataEntity | null {
    if (this.realpsdataentity != null) return this.realpsdataentity;
    const value = this.M.getRealPSDataEntity;
    if (value == null) {
      return null;
    }
    this.realpsdataentity = this.getPSModel4('dataentity.IPSDataEntity', value, 'getRealPSDataEntity') as IPSDataEntity;
    return this.realpsdataentity;
  }

  get realPSDataEntity(): IPSDataEntity | null {
    return this.getRealPSDataEntity();
  }

  getRealPSDataEntityMust(): IPSDataEntity {
    const value = this.getRealPSDataEntity();
    if (value == null) {
      throw new Error('未指定实际属性所在实体');
    }
    return value;
  }

  protected relatedpsdefield: IPSDEField | null = null;

  getRelatedPSDEField(): IPSDEField | null {
    if (this.relatedpsdefield != null) return this.relatedpsdefield;
    const value = this.M.getRelatedPSDEField;
    if (value == null) {
      return null;
    }
    this.relatedpsdefield = this.getRelatedPSDataEntityMust().findPSDEField(value);
    return this.relatedpsdefield;
  }

  get relatedPSDEField(): IPSDEField | null {
    return this.getRelatedPSDEField();
  }

  getRelatedPSDEFieldMust(): IPSDEField {
    const value = this.getRelatedPSDEField();
    if (value == null) {
      throw new Error('未指定链接属性');
    }
    return value;
  }

  protected relatedpsdataentity: IPSDataEntity | null = null;

  getRelatedPSDataEntity(): IPSDataEntity | null {
    if (this.relatedpsdataentity != null) return this.relatedpsdataentity;
    const value = this.M.getRelatedPSDataEntity;
    if (value == null) {
      return null;
    }
    this.relatedpsdataentity = this.getPSModel4('dataentity.IPSDataEntity', value, 'getRelatedPSDataEntity') as IPSDataEntity;
    return this.relatedpsdataentity;
  }

  get relatedPSDataEntity(): IPSDataEntity | null {
    return this.getRelatedPSDataEntity();
  }

  getRelatedPSDataEntityMust(): IPSDataEntity {
    const value = this.getRelatedPSDataEntity();
    if (value == null) {
      throw new Error('未指定链接属性所在实体');
    }
    return value;
  }

  get valueFormat(): string {
    return this.M.valueFormat;
  }

  get dynaStorageDEField(): boolean {
    return this.M.dynaStorageDEField != null ? this.M.dynaStorageDEField : false;
  }

  get linkDEField(): boolean {
    return this.M.linkDEField != null ? this.M.linkDEField : false;
  }

  get phisicalDEField(): boolean {
    return this.M.phisicalDEField != null ? this.M.phisicalDEField : true;
  }

  get uIAssistDEField(): boolean {
    return this.M.uIAssistDEField != null ? this.M.uIAssistDEField : false;
  }

  get cls(): string {
    return 'PSLinkDEFieldImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'dataentity.defield.IPSLinkDEField') return true;
    return super.instanceof(cls);
  }
}
